package reflect

import (
	"fmt"
	"reflect"
)

func walk(i interface{}, fn func(str string)) {
	val := reflect.ValueOf(i)
	if val.Kind() == reflect.Ptr {
		val = val.Elem()
	}
	fmt.Println(val.Kind())
	switch val.Kind() {
	case reflect.String:
		fn(val.String())
	case reflect.Array, reflect.Slice:
		for i := 0; i < val.Len(); i++ {
			walk(val.Index(i).Interface(), fn)
		}
	case reflect.Struct:
		fmt.Println(val.NumField())
		for i := 0; i < val.NumField(); i++ {
			walk(val.Field(i).Interface(), fn)
		}
	case reflect.Map:
		for _, key := range val.MapKeys() {
			walk(val.MapIndex(key).Interface(), fn)
		}
	}

}
